package collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.Objects;

/**jdk1.5版本才更新的新循环
 * */
public class NewForDemo {
    public static void main(String[] args) {

        String[]arr={"1","2","3","4","5"};
        for (String s:arr){

            System.out.println(s);
        }
        System.out.println("==================================");
        Collection c=new ArrayList<>();
        c.add("7");
        c.add("8");
        c.add("9");
        c.add("6");
        c.add("5");

        Iterator iterator = c.iterator();//调用迭代器
        while (iterator.hasNext()){//hasNext()调用是否有下一个元素的方法
            String next = (String) iterator.next();//next()获取元素方法
            System.out.println(next);//输出
        }
        System.out.println("以下就是增强for循环=========");
        for (Object obj:c){
            String obj1 = (String) obj;
            System.out.println(obj1);
        }


    }
}
